document.write('<script type="text/javascript" src="../static/js/back/utils.js"></script>');
document.write('<script type="text/javascript" src="../static/js/back/ajax.js"></script>');
var _url_ = '../table/addTablesInfo.do';
var _url_edit = '../table/updateTablesInfo.do';
var _url_list = '../shop/getShopOrderProfitInfo';
var _url_id = '../table/getTablesById';
var _map = {};
var _pageNum = 1;
var _type ;
var spid="";
  $(function(){
	   spid = getCookie("shop_id");
	  _type = getUrlParam("type");
	  console.log(_type);
	  if(_type === "add"){
		 // getTypeListAdd();
		  _showData = {};
		  $("#shopId").val(spid);
	  }else if(_type === "edit"){
		  showEditData();
		  _url_ = _url_edit;
	  }else{
//		  getTypeList();
		  getZHInfo();
		  var uid = getCookie("uid");
		  _map["shopUserId"] = uid;
		  getList();
	  }
  });
$(function(){
	  $("body").on("click",".mypage span",function(){
		  _pageNum = $(this).attr("data-status");
		  getList();
	  });
	  $(".search-btn").click(function(){
		  if($("#province").val() != "请选择省"){
			  _map['addressProvince'] = $("#province").val();
		  }else{
			  _map['addressProvince'] = "";
		  }
		  if($("#city").val()!="请选择市"){
			  _map['addressCity'] = $("#city").val();
		  }else{
			  _map['addressCity'] = "";
		  }
		  if($("#city").val()!="请选择区/县"){
			  _map['addressArea'] = $("#area").val();
		  }else{
			  _map['addressArea'] = "";
		  }
		  
		  _map.startTime = $("#start").val();
		  var end =$("#end").val();
		  if(end){
			  end =  addDate(end,1);
		  }
		  _map.endTime =  end;
		  	_pageNum = 1;
		  	getZHInfo();
		  	getList();
	  })
	  
	   $(".exportData").click(function(){
		   var url_ = "../excel/exportShopDataStatis?startTime="+$("#start").val()+"&endTime="+$("#end").val();
		   var pro= "";
		   var cit = "";
		   if($("#province").val() != "请选择省"){
			   url_ += "&addressProvince="+$("#province").val();
			  }
			  if($("#city").val()!="请选择市"){
				  url_ += "&addressCity="+$("#city").val();
			  }
			  if($("#city").val()!="请选择市"){
				  url_ += "&addressArea="+$("#area").val();
			  }
		   window.open(url_);
	   })
	  
});
  function getList(){
	  _map['pageNum'] = _pageNum;
	  _ajax_get_token(_url_list,_map,function(res){
		  console.log(res);
		  console.log(res.returnObject);
		  
		  if(!res.returnObject||res.returnObject.length<=0 ){
			  $(".layui-table tbody").html("");
			  $(".no-more-data").show();
			  $(".mypage").hide();
			  $(".x-right").text("共有数据：0 条");
			  return;
		  }else{
			  $(".mypage").show();
			  $(".no-more-data").hide();
		  }
		  var html = "";
		  var stat = "" , statHtml = "";
		  showPageInfo(res.returnObject);
		  $(".x-right").text("共有数据："+res.returnObject.total +" 条");
		  var startRow = res.returnObject.startRow;
		  var html,stat,statStr,typeStr,sendTypeStr;
		  $.each(res.returnObject.list,function(i,v,arr){
			  html+=' <tr><td>'
// 	             +' <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="'+v.id+'" ><i class="layui-icon">&#xe605;</i></div>'
// 	             +' </td>                                                                                                                  '
// 	             +' <td>'
 	             +(i+startRow)+'</td>                                                                                                             '
 	             +' <td>'+v.shopTitle
 	             +'</td>                                                                                           '
// 	             +' <td align="center"><a target="_blank" href="'+v.adUrl+'"><img  src="'+v.adPic+'" height=50 widht=50 ></a></td>                                                                                                      '
// 	             +' <td>'+v.adUrl+'</td>                                                                                                      '
 	             +' <td>'+v.addressProvince+""+v.addressCity+v.addressArea+'</td>                                                                                                      '
 	             +' <td>'+(v.shopInCharge/100.0)+'</td>                                                                                                      '
 	             +' <td>'+v.orderCount+'</td>                                                                                                      '
 	             +' <td >'+(v.payCount / 100).toFixed(2)+'</td>'
 	             +' <td >'+(v.outCount / 100).toFixed(2)+'</td>'
 	             +' <td >'+(v.roomCount / 100).toFixed(2)+'</td>'
 	             +' <td >'+(v.wxCount / 100).toFixed(2)+'</td>'
 	             +' <td >'+(v.xxCount / 100).toFixed(2)+'</td>'
 	            +' <td class="td-manage">'
 	            +'   <a title="查看"  class="tix-record"  onclick="x_admin_show(\'财务对账-'+v.shopTitle+'\',\'./money~money-bills.html?shopId='+v.id+'\',\'\',\'\',true)" href="javascript:;">                       '
			  		+'           查看                                                                         '
			  		+'   </a></td>'
 	             +' </tr>';
		  });
		  $(".one .layui-table tbody").html(html);
	  });
  }
  function getZHInfo(){
	  var _map2 = {};
	  if($("#province").val() != "请选择省"){
		  _map2['addressProvince'] = $("#province").val();
	  }else{
		  _map2['addressProvince'] = "";
	  }
	  if($("#city").val()!="请选择市"){
		  _map2['addressCity'] = $("#city").val();
	  }else{
		  _map2['addressCity'] = "";
	  }
	  _map2.startTime = $("#start").val();
	  var end =$("#end").val();
	  if(end){
		  end =  addDate(end,1);
	  }
	  _map2.endTime = end;
	  console.log(_map2);
	  _ajax_post_token('../shop/getDataStatisInfo.do',_map2,function(res){
		  console.log(res);
		  if(res.resultCode == 1000){
			 var dd = res.returnObject;
			 $(".money").eq(0).text(dd.shopCount);
			 $(".money").eq(1).text(dd.cyCount);
			 $(".money").eq(2).text(dd.csCount);
			 $(".money").eq(3).text(dd.wxCount);
			 $(".money").eq(4).text((dd.yyeCount/100).toFixed(2));
			 $(".money").eq(5).text((dd.wxyyeCount/100).toFixed(2));
			 $(".money").eq(6).text((dd.xxyyeCount/100).toFixed(2));
			 $(".money").eq(7).text(dd.orCount);
			 $(".money").eq(8).text(dd.outCount);
			 $(".money").eq(9).text(dd.roomCount);
		  }
	  });
  }
function showRecord(){
	 _map['shopId'] = spid;
	  _map['pageNum'] = _pageNum;
	  _map['tranType'] = 2;
	  _ajax_get_token(_url_list,_map,function(res){
		  console.log(res);
		  console.log(res.returnObject);
		  if(!res.returnObject||res.returnObject.length<=0 ){
			  $(".layui-table tbody").html("");
			  $(".no-more-data").show();
			  $(".mypage").hide();
			  return;
		  }else{
			  $(".mypage").show();
			  $(".no-more-data").hide();
		  }
		  var html = "";
		  var stat = "" , statHtml = "";
		  showPageInfo(res.returnObject);
		  $(".x-right").text("共有数据："+res.returnObject.total +" 条");
		  var html,stat,statStr,typeStr,sendTypeStr;
		  $.each(res.returnObject.list,function(i,v,arr){
			  console.log(v);
			  if(v.tranType == 1){
				  typeStr = "外卖订单";
			  }else if(v.tranType == 2){
				  typeStr = "余额提现";
			  }
			  
			  if(v.type == 1){
				  typeStr+="退换";
			  }
			  if(v.status == 1){
				  statStr = "提现成功";
			  }else if (v.status == 2) {
				  statStr = "提现失败";
			  }else {
				  statStr = '审核中';
			  }
			  html+=' <tr><td>'
//	             +' <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="'+v.id+'" ><i class="layui-icon">&#xe605;</i></div>'
//	             +' </td>                                                                                                                  '
//	             +' <td>'
	             +(i+1)+'</td>                                                                                                             '
	             +' <td>'+v.serialNumber 
	             +'</td>                                                                                           '
//	             +' <td align="center"><a target="_blank" href="'+v.adUrl+'"><img  src="'+v.adPic+'" height=50 widht=50 ></a></td>                                                                                                      '
//	             +' <td>'+v.adUrl+'</td>                                                                                                      '
	             +' <td >'+(v.amount / 100).toFixed(2)+'</td>'
	             +' <td>'+v.createTime+'</td>                                                                                                      '
	             +' <td >'+statStr+'</td>'
	             +' </tr>';
		  });
		  $(".two .layui-table tbody").html(html);
	  });
}